package cn.hicard.risk.dao.bd.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import cn.hicard.core.Page;
import cn.hicard.core.PageResult;
import cn.hicard.core.Where;
import cn.hicard.risk.dao.BaseDao;
import cn.hicard.risk.dao.bd.BankcallDao;
import cn.hicard.risk.entity.BdBankcall;
import cn.hicard.risk.entity.JzgRiskestimate;
import cn.hicard.risk.entity.LimitFreezeinfo;

@Repository
public class BankcallDaoImpl extends BaseDao<BdBankcall> implements BankcallDao{

	public void save(BdBankcall bankcall)throws Exception{
		super.save(bankcall);
	}
	
	@Override
	public void update(BdBankcall bankcall) throws Exception {
		super.update(bankcall);		
	}
	
	
	@Override
	public PageResult<BdBankcall> search(BdBankcall bankcallStart,BdBankcall bankcallEnd, Page page)
			throws Exception {
		String sql = "SELECT c.* FROM bd_bankcall AS c WHERE 1=1 order by addtime desc ";
		String countSql = "SELECT COUNT(*) FROM bd_bankcall AS c WHERE 1=1 ";
		Where where = new Where(BdBankcall.class);
		
		if(bankcallStart!=null){
			where.addEqual("hmid", bankcallStart.getHmid());
			where.addLike("merchname", bankcallStart.getMerchname());
			where.addEqual("orderno", bankcallStart.getOrderno());
			where.addLike("orgno", bankcallStart.getOrgno());
			where.addEqual("type", bankcallStart.getType());
			where.addEqual("ischargeback", bankcallStart.getIschargeback());
			where.addEqual("transamount", bankcallStart.getTransamount());
		}
	
		if(bankcallEnd!=null){
			where.addBetween("transtime", bankcallStart.getTranstime(),bankcallEnd.getTranstime());	
			where.addBetween("informtime", bankcallStart.getInformtime(),bankcallEnd.getInformtime());	
			where.addBetween("returntime", bankcallStart.getReturntime(),bankcallEnd.getReturntime());
		}
		
		sql += where.queryString();
		countSql += where.queryString();
		
		PageResult<BdBankcall> result = new PageResult<BdBankcall>();
		result.setDataList(super.findBySqlPage(sql, page, where.getParams()));
		result.setResultCount(super.findCountBySql(countSql, where.getParams()));
		
		return result;
	}

    public List<BdBankcall> findList(BdBankcall bankcallStart,BdBankcall bankcallEnd) throws Exception{
		
    	String hql = " FROM BdBankcall WHERE 1=1 ";
    	Where where = new Where(BdBankcall.class);
		
    	if(bankcallStart!=null){
    		where.addEqual("hmid", bankcallStart.getHmid());
    		where.addLike("merchname", bankcallStart.getMerchname());
    		where.addEqual("orderno", bankcallStart.getOrderno());
    		where.addLike("orgno", bankcallStart.getOrgno());
    		where.addEqual("type", bankcallStart.getType());
    		where.addEqual("ischargeback", bankcallStart.getIschargeback());
    		where.addEqual("transamount", bankcallStart.getTransamount());

    	}
	
		if(bankcallEnd!=null){
			where.addBetween("transtime", bankcallStart.getTranstime(),bankcallEnd.getTranstime());	
			where.addBetween("informtime", bankcallStart.getInformtime(),bankcallEnd.getInformtime());	
			where.addBetween("returntime", bankcallStart.getReturntime(),bankcallEnd.getReturntime());
		}
		
		hql += where.queryString();
		List<BdBankcall> list = super.findByHql(hql, where.getParams());
		return list;
    }
    
    public  List<BdBankcall> findListByWhere(Where where) throws Exception{
    	String hql = " FROM BdBankcall WHERE 1=1 ";
    	hql += where.queryString();
		List<BdBankcall> list = super.findByHql(hql, where.getParams());
		return list;
    }

}
